package fileAndIO;

import org.junit.Test;

import java.io.*;


// 序列化
public class Test7 {
    @Test
    public void test() throws IOException {
        // 序列化
        Employee employee = new Employee();
        employee.name = "ccc";
        employee.address = "ch";
        ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream("employee.txt"));
        outputStream.writeObject(employee);
        outputStream.close();
    }

    @Test
    public void test2() throws IOException, ClassNotFoundException {
        // 反序列化
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("employee.txt"));
        Object o = objectInputStream.readObject();
        Employee o1 = (Employee) o;
        System.out.println(o1.name);
        System.out.println(o1.address);

        objectInputStream.close();
    }
}

class Employee implements Serializable {
    public String name;
    public String address;
}